﻿namespace ScrumLite.Services.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Rhino.Mocks;
    using ScrumLite.Services.Contracts;
    using ScrumLite.Data;
    using System.Collections.ObjectModel;

    [TestClass]
    public class LinqPeopleServiceFixture
    {
        MockRepository mocks;

        [TestInitialize]
        public void Initialize()
        {
            this.mocks = new MockRepository();
        }

        [TestMethod]
        public void ShouldGetPersonEducation()
        {
            ScrumLite.Data.IUserStore store = this.mocks.DynamicMock<ScrumLite.Data.IUserStore>();

            ScrumLite.Data.Education[] expected = new ScrumLite.Data.Education[]
            {
                new ScrumLite.Data.Education { id = Guid.NewGuid(), samAccountName = "southy", title = "bachelor", certificator = "St. Andrews", completed = true },
                new ScrumLite.Data.Education { id = Guid.NewGuid(), samAccountName = "southy", title = "engineer", certificator = "Princeton", completed = true }
            };

            Expect.Call(store.RetrieveUserEducation(null))
                .Return(expected)
                .Callback(new Func<String, bool>(g => { return true; }));
            mocks.ReplayAll();

            LinqPeopleService service = new LinqPeopleService(store);

            ScrumLite.Services.Contracts.Education[] actual = service.GetPersonEducation("southy");

            Assert.AreEqual(2, actual.Count());
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.AreEqual(expected[i].id, actual[i].Id);
                Assert.AreEqual(expected[i].samAccountName, actual[i].PersonId);
                Assert.AreEqual(expected[i].title, actual[i].Title);
                Assert.AreEqual(expected[i].certificator, actual[i].Certifier);
                Assert.AreEqual(expected[i].completed, actual[i].Completed);
            }
        }

        [TestMethod]
        public void ShouldGetPersonAbilities()
        {
            ScrumLite.Data.IUserStore store = this.mocks.DynamicMock<ScrumLite.Data.IUserStore>();

            ScrumLite.Data.Ability[] expected = new ScrumLite.Data.Ability[]
            {
                new ScrumLite.Data.Ability { id = Guid.NewGuid(), name = "ASP.NET" },
                new ScrumLite.Data.Ability { id = Guid.NewGuid(), name = "C#" }
            };

            Expect.Call(store.RetrieveUserAbilities(null))
                .Return(expected)
                .Callback(new Func<String, bool>(g => { return true; }));
            mocks.ReplayAll();

            LinqPeopleService service = new LinqPeopleService(store);

            ScrumLite.Services.Contracts.Ability[] actual = service.GetPersonAbilities("southy");

            Assert.AreEqual(2, actual.Count());
            for (int i = 0; i < expected.Count(); i++)
            {
                Assert.AreEqual(expected[i].id, actual[i].Id);
                Assert.AreEqual(expected[i].name, actual[i].Name);
            }
        }
    }
}
